package top.hugo.generator.service;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import top.hugo.common.constant.ReqTokenConstant;

import java.time.LocalTime;


/**
 * @Title: GpApiDataStorageService
 * @Description:
 * @Auther: kuanghua
 * @create 2025/3/8 12:15:46
 */
@Service
@AllArgsConstructor
public class GpApiDataStorageService {
    /*9:15储存竞价一字版和涨停接口数据*/
    //    @Scheduled(cron ="*/6 * * * * ?")
    //    public void sayHello() {
    //        storageApiData();
    //        System.out.println("hello");
    //    }
    //
    //
    //    /*9:15储存竞价一字版和涨停接口数据，周一至周五的9:15:00到9:25:00执行*/
    //    @Scheduled(cron = "0 * 9 * * MON-FRI")
    //    public void executeTask() {
    //        LocalTime now = LocalTime.now(); // 获取当前时间
    //        LocalTime startTime = LocalTime.of(9, 15, 0); // 开始时间 9:15:00
    //        LocalTime endTime = LocalTime.of(9, 25, 0); // 结束时间 9:25:00
    //        // 判断当前时间是否在 9:15:00 到 9:25:00 之间
    //        if (now.isAfter(startTime) && now.isBefore(endTime)) {
    //            // 在时间范围内每秒执行一次任务
    //            while (LocalTime.now().isBefore(endTime)) {
    //                // 这里是你要执行的逻辑
    //                System.out.println("定时任务执行了，当前时间: " + LocalTime.now());
    //                try {
    //                    Thread.sleep(1000); // 暂停 1 秒
    //                } catch (InterruptedException e) {
    //                    e.printStackTrace();
    //                }
    //            }
    //        }
    //    }

    //   /*储存竞价一字板和竞价数据*/
    //    public void storageApiData(){
    //        //获取数
    //
    //    }

    /**
     * 竞价一字板
     * @param jsonString
     * @return
     */
    public JSON limitBoard(String jsonString) {
        String resData = HttpRequest.post("https://eq.10jqka.com.cn/call_auction_v2/stock_chance/v1/history_list/limit_board")
                .header("Cookie", ReqTokenConstant.CommonCookie1)
                .body(jsonString).execute().body();
        return JSONUtil.parse(resData);
    }



    /*集合竞价全部票接口*/
    public JSON callWarn(String jsonString) {
        String resData = HttpRequest.post("https://eq.10jqka.com.cn/call_auction_v2/stock_chance/v1/history_list/call_warn")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .body(jsonString).execute().body();
        return JSONUtil.parse(resData);
    }

    /*交易日期*/
    public JSON getTradeDay(String date) {
        String resData = HttpRequest.get("https://data.10jqka.com.cn/dataapi/limit_up/trade_day?date="+date+"&stock=stock&next=1&prev=365")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .execute().body();
        return JSONUtil.parse(resData);
    }


    /*涨停票*/
    public JSON limit_up_pool(String date) {
        String resData = HttpRequest.get("https://data.10jqka.com.cn/dataapi/limit_up/limit_up_pool?date="+date+"&page=1&limit=200&field=199112%2C10%2C9001%2C330323%2C330324%2C330325%2C9002%2C330329%2C133971%2C133970%2C1968584%2C3475914%2C9003%2C9004&filter=HS%2CGEM2STAR&order_field=330329&order_type=1")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .execute().body();
        return JSONUtil.parse(resData);
    }

    /*涨停票*/
    public JSON limit_up_pools(String date) {
        String resData = HttpRequest.get("https://data.10jqka.com.cn/dataapi/limit_up/limit_up_pool?&date="+date+"&page=2&limit=200&filter=HS,GEM2STAR&order_type=1&field=330329,330323,9001,199112,10,330324,330325,9002,133971,133970,1968584,3475914,9003,9004&order_field=330329")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .execute().body();
        return JSONUtil.parse(resData);
    }


    /*炸板票*/
    public JSON open_limit_pool(String date) {
        String resData = HttpRequest.get("https://data.10jqka.com.cn/dataapi/limit_up/open_limit_pool?"+date+"page=1&limit=100&field=199112%2C9002%2C1968584%2C19%2C3475914%2C48%2C9003%2C10%2C9004&filter=HS%2CGEM2STAR&order_field=199112&order_type=0")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .execute().body();
        return JSONUtil.parse(resData);

    }


    /*涨停和炸板状态*/
    public JSON limit_up_change() {
        String resData = HttpRequest.get("https://data.10jqka.com.cn/dataapi/limit_up/change?type=init&_=1732683855166")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .execute().body();
        return JSONUtil.parse(resData);
    }


    /*冲刺涨停*/
    public JSON limit_up(String date) {
        String resData = HttpRequest.get("https://data.10jqka.com.cn/dataapi/limit_up/limit_up?&date="+date+"&page=1&limit=30&field=199112%2C10%2C48%2C1968584%2C19%2C3475914%2C9003%2C9004&filter=HS%2CGEM2STAR&order_field=199112&order_type=0")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .execute().body();
        return JSONUtil.parse(resData);
    }

    /*获取板块列表*/
    public JSON get_block_list(String jsonString) {
        String resData = HttpRequest.post("https://dq.10jqka.com.cn/interval_calculation/block_info/v1/get_block_list")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .body(jsonString).execute().body();
        return JSONUtil.parse(resData);
    }


    /*获取板块个股列表*/
    public JSON get_stock_list_by_block(String jsonString) {
        String resData = HttpRequest.post("https://dq.10jqka.com.cn/interval_calculation/stock_info/v1/get_stock_list_by_block")
                .header("Cookie", ReqTokenConstant.CommonCookie2)
                .body(jsonString).execute().body();
        return JSONUtil.parse(resData);
    }


    /*i问财查询接口*/
    public JSON get_robot_data(String jsonString,String hexin) {
        String resData = HttpRequest.post("https://www.iwencai.com/customized/chart/get-robot-data")
                .header("Cookie", "cid=69a2607e55804e996e8ee5fe60ede9941707998559")
                .header("hexin-v", hexin)
                .body(jsonString).execute().body();
        return JSONUtil.parse(resData);
    }


    /*自选板块添加接口*/
    public JSON self_stock_add(String jsonString,String cookie) {
        JSON parseData = JSONUtil.parse(jsonString);
        String resData = HttpRequest
                .post("https://www.iwencai.com/iwencai/userinfo/iwc/userinfo/self-stock/plate/add")
                .header("Cookie", cookie)
                .body(JSONUtil.toJsonStr(parseData)).charset("UTF-8")              // 设置JSON请求体
                .contentType("application/json") // 明确设置Content-Type
                .execute().body();
        return JSONUtil.parse(resData);
    }
    /*自选添加接口*/
    public JSON self_stock_add_zx(String jsonString,String cookie) {
        JSON parseData = JSONUtil.parse(jsonString);
        String resData = HttpRequest
                .post("https://www.iwencai.com/iwencai/userinfo/iwc/userinfo/self-stock/index/add")
                .header("Cookie", cookie)
                .body(JSONUtil.toJsonStr(parseData)).charset("UTF-8")              // 设置JSON请求体
                .contentType("application/json") // 明确设置Content-Type
                .execute().body();
        return JSONUtil.parse(resData);
    }
}
